import time
from python_baway.common.xcommon import xcheck

FMT = '%Y-%m-%d %H:%M:%S'
with open('x_log_datetime.tmp.txt', 'a+') as xfile:
    xtime_str = time.strftime(FMT, time.localtime())
    xfile.write(xtime_str + '\n')
    xfile.flush()
    xfile.seek(0)
    while True:
        xline = xfile.readline()
        if not xline:
            break
        xline = xline[:-1]
        try:
            xst = repr(time.strptime(xline, FMT))
        except ValueError as ex:
            xst = repr(ex)
        print(xline + ' => ' + xst)
